/*! lzf */

jQuery.fn.pagination = function (e, u) {
    return u = jQuery.extend({
        items_per_page: 10,
        num_display_entries: 10,
        current_page: 0,
        link_to: "#",
        prev_text: "Prev",
        next_text: "Next",
        ellipse_text: "...",
        prev_show_always: !0,
        next_show_always: !0,
        callback: function () {
            return !1
        }
    }, u || {}), this.each(function () {
        function _() {
            return Math.ceil(e / u.items_per_page)
        }

        function l(e, t) {
            p = e, n();
            var a = u.callback(e, c);
            return a || (t.stopPropagation ? t.stopPropagation() : t.cancelBubble = !0), a
        }

        function n() {
            c.empty();
            var e, t, a,
                n = (e = Math.floor(u.num_display_entries / 2), t = _(), a = t - u.num_display_entries + 1, [e < p ? Math.max(Math.min(p - e, a), 1) : 1, e < p ? Math.min(p + e, t) : Math.min(u.num_display_entries, t)]),
                s = _(), r = function (e, t) {
                    if (e = e < 1 ? 1 : e < s ? e : s, t = jQuery.extend({
                        text: e,
                        classes: ""
                    }, t || {}), e == p) var a = jQuery("<span class='current'>" + t.text + "</span>"); else if (u.link_to && "#" != u.link_to) a = jQuery("<a>" + t.text + "</a>").attr("href", u.link_to.replace(/__id__/, e)); else a = jQuery("<a>" + t.text + "</a>").bind("click", (n = e, function (e) {
                        return l(n, e)
                    })).attr("href", "#");
                    var n;
                    t.classes && a.addClass(t.classes), c.append(a)
                };
            r(1, {
                text: "棣栭〉",
                classes: "last"
            }), u.prev_text && (1 < p || u.prev_show_always) && r(p - 1, {text: u.prev_text, classes: "prev"});
            for (var i = n[0]; i <= n[1]; i++) r(i);
            u.next_text && (p < s || u.next_show_always) && r(p + 1, {
                text: u.next_text,
                classes: "next"
            }), r(s, {text: "鏈〉", classes: "last"})
        }

        var p = parseInt(u.current_page);
        e = !e || e < 1 ? 1 : e, u.items_per_page = !u.items_per_page || u.items_per_page < 1 ? 1 : u.items_per_page;
        var c = jQuery(this);
        this.selectPage = function (e) {
            l(e)
        }, this.prevPage = function () {
            return 1 < p && (l(p - 1), !0)
        }, this.nextPage = function () {
            return p < _() && (l(p + 1), !0)
        }, n(), u.callback(p, this)
    })
};